package com.gxz.controller;

import com.gxz.common.Result;
import com.gxz.exception.BussinessException;
import com.gxz.exception.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ProjectExceptionAdvice {

    @ExceptionHandler(BussinessException.class)
    public Result doBusinessException(BussinessException e) {
        Result result = new Result(e.getCode(), null, e.getMessage());
        System.out.println("11111" + e.getCode() + e.getMessage());
        return result;
    }

    @ExceptionHandler(SystemException.class)
    public Result doSystemException(SystemException e) {
        Result result = new Result(e.getCode(), e.getMessage());
        return result;
    }

    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e) {
        Result result = new Result(Result.UNKNOW_ERR_CODE, e.getMessage());
        return result;
    }
}
